<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="structures.User"%>
<%@ page import="structures.AD"%>
<%@ page import="structures.ADsList"%>
<%User user = (User) session.getAttribute("user");%>
<%	ADsList adsList = (ADsList) session.getAttribute("adsList");
	session.removeAttribute("adsList");
	String imageSource = "http://localhost:8080/DatabaseRESTWebService/GetADImage?idAdvertisement=";%>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>TiVendoIo - Advertisements</title>

    <!-- Bootstrap -->
    <link href="/serviceTechnologies/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" rel="stylesheet">
    <link href="css/style.css" rel = "stylesheet">
    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script type="text/javascript">
	$(document).ready(function(){
		$('#footer').load('/serviceTechnologies/common/footer.jsp');
		$('#navbar').load('/serviceTechnologies/common/navbar.jsp');
	});
	</script>
	
  </head>
  <body>
 	<div id="navbar"></div>
   <div class="container">
  		<br>
		<%if(adsList==null || adsList.getAdsList().size()==0){ %>
			<h3>No Ads in the database!</h3>
		<%  }else{
  		%>
		
  		<%for(AD advertisement: adsList.getAdsList()){ 
  			%>
  			
  				<div class = "row">
  					<div class = "col-md-2"></div>
  					<div class = "col-md-3">
  					<img src="<%=imageSource + advertisement.getIdAdvertisement()%>" id="Image1" alt="" class = "img-rounded" style="max-width: 250px; max-height: 200px;">
  					</div>
  					<div class = "col-md-1">
  					<p>
  						<b>Title:</b><br>
   						<b>Description:</b><br>
   						<b>Price:</b><br>
   						<br><br>
   						<a href="./ShowAD?idAdvertisement=<%=advertisement.getIdAdvertisement()%>&WikiInfo=true">
  							<button class="btn btn-default btn-primary btn-sm"><span class="glyphicon glyphicon-eye-open"></span> Take a Look!</button>
  						</a>
   					</p>
  					</div>
   					<div class = "col-md-1">
   					<p>
   						<%=advertisement.getTitle()%> <br>
   						<%=advertisement.getDescription()%> <br>
   						<%=advertisement.getPrice()%> <br>
   					</p>
   					</div>
				
				
  				<%if(advertisement.getBoughtBy()!=null){%>
  					<p><span class="glyphicon glyphicon-ok-circle"></span> Already Bought!</p>
  				<%}%>
				</div>	
  				<br>
  		<%  }
  		%>
  		
  		
  		<%if(adsList.getHasPredecessors()){%>
  			<a href="./TiVendoIoAds?starterId=<%=adsList.getAdsList().get(0).getIdAdvertisement()%>&method=predecessors&limit=10">
  				<button>Previous</button>
  			</a>
  		<%  }
  		%>
  		
  		<%if(adsList.getHasSuccessors()){%>
  			<a href="./TiVendoIoAds?starterId=<%=adsList.getAdsList().get(adsList.getAdsList().size()-1).getIdAdvertisement()%>&method=successors&limit=10">
  				<button>Next</button>
  			</a>
  		<%  }
		}
  		%>

    </div> <!-- End Container -->
 	
 	
 	<div id="footer">
      
    </div>
 	<!-- End footer -->
 	
 	
  </body>
 </html>